const path = require('path');
module.exports = app => {
  const config = {};

  /**
   * 端口配置
   * @type {{listen: {port: number}}}
   */
  config.cluster = {
    listen: {
      port: 3000,
    },
  };

  /**
   * 静态服务
   * @type {{maxAge: number, prefix: string, dir: string[]}}
   */
  config.static = {
    maxAge: 0, // maxAge 缓存，默认 1 年
    prefix: '/',
    dir: [path.join(app.baseDir, 'public'), path.join(app.baseDir, 'static'), path.join(app.baseDir, 'dist')],
  };

  /**
   * 视图
   * @type {{mapping: {".ejs": string}}}
   */
  config.view = {
    root: [
      path.join(app.baseDir, 'app/view'),
      path.join(app.baseDir, 'dist'),
    ].join(','),
    mapping: {
      '.ejs': 'ejs',
      '.html': 'ejs',
    },
  };

  // ejs 模板
  config.ejs = {};

  // cookie 加密KEY
  config.keys = 'www.xxmi.cn';

  /**
   * 安全配置
   * @type {{csp: {ignore: string}, csrf: {enable: boolean}}}
   */
  config.security = {
    xframe: {
      enable: false,
    },
    csrf: {
      enable: false,
    },
    csp: {
      ignore: '/',
    },
    domainWhiteList: ['*'], // 允许的跨域请求的白名单
  };

  // 跨域
  config.cors = {
    credentials: true,
  };

  return config;
};
